<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原始需求详情</title>
    <link href="../css/list-detial.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<!--header-->
<header id="header" class="header">
    <div class="header-info left"><i></i><a href="pm-need-list.html">原始需求列表</a>&nbsp;>&nbsp;原始需求详情</div>
    <div class="right-user right">
         <div class="clear t" >             <div id="headusername" class="role"></div>             <div class="icon"></div>         </div>
        <div class="head-down">
            <ul><li><a href="edit-pwd.html">修改密码</a></li><li><a onclick="loginOut()">退出系统</a></li></ul></div><div>
    </div>
    </div>
</header>
<!--menu-->
<aside id="aside" class="aside">
    <div class="logo">运营平台</div>
    <ul class="menu" id="asidemenu">
    </ul>
</aside>
<!--content-->

<div class="content">
    <div class="page-inner">
        <div class="commit-new-item"><a onclick="creatRelativeLink()" class="btn" style="width: 100px" id="creatRelativeNeed">创建相关需求&nbsp;<b>+</b></a>&emsp;<a href="javascript:" id="creatShareid" onclick="creatShare()" style="width: 100px" class="btn">关联已有需求&nbsp;<b>+</b></a></div>
        <div class="page-content">
            <div class="table-head clear"><div class="left document-name" id="document-name"><i class="bug-i"></i></div><div class="right edit" id="needEdit" style="display: none"><a class="sure" onclick="edit()">编辑</a></div></div>
            <div class="table-cont">
                <table class="content-table">
                    <tr>
                        <td>需求名称：<!-- <input type="checkbox" disabled="disabled" checked="checked" name=""> --></td>
                        <td colspan="2" id="needName"></td>
                    </tr>
                    <tr>
                        <td>来源：</td>
                        <td id="projectName"> </td>
                        <td>需求方：</td>
                        <td  id="needSide"></td>
                    </tr>
                    <tr>
                        <td>类别：</td>
                        <td id="typeList">新需求</td>
                        <td>产品:</td>
                        <td id="productList"></td>
                    </tr>
                    <tr>
                        <td>使用平台：</td>
                        <td id="platformList"></td>
                        <td>功能模块：</td>
                        <td id="functionList"></td>
                    </tr>
                    <tr>
                        <td>紧急程度：</td>
                        <td id="levelList"></td>
                        <td>可靠度：</td>
                        <td id="reliableList"></td>
                    </tr>
                    <tr>
                        <td>需求场景：</td>
                        <td colspan="3" id="scenario"></td>
                    </tr>

                    <tr class="area">
                        <td>现有方案：</td>
                        <td colspan="3" id="nowSolution">
                            
                        </td>
                    </tr>
                    <tr class="area">
                        <td>建议方案：</td>
                        <td colspan="3" id="sugSolution">
                            
                        </td>
                    </tr>
                    <tr class="area">
                        <td>附件：</td>
                        <td colspan="3">
                             <ul class="addAttachmentList" id="addAttachmentList">
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>

            <div class="table-head clear"><div class="left document-name"><i class="bug-i"></i>相关产品需求</div></div>
            <div class="table-cont">
                <table class="relative-list">
                    <thead>
                        <tr>
                            <th>产品名称</th>
                            <th>功能模块</th>
                            <th>需求名称</th>
                            <th>优先级</th>
                            <th>处理状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="relativeList">
                       
                    </tbody>
                    
                </table>
            </div>
            
        </div>
    </div>
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.cookie.js"></script>
<script src="../js/common.js"></script>

<script type="text/javascript">

    var _id = getUrlId();
    
    function creatRelativeLink(){
        location.href = 'pm-commite-relative.html?id='+_id+'&name='+$('#needName').html();
    }

    function edit(){
        location.href = 'pm-need-detail-mems-edit.html?id='+_id;
    }

    //权限控制
    var roleid = $.cookie('userrole');
    function cannotrelative(){

        if(roleid == 1 || roleid == 2 || roleid == 3){
            $('#creatShareid').remove();
            $('#creatRelativeNeed').remove()
        }
    }
    cannotrelative()
    var attachment = new attachment();
    function updata(){
        var url  = _ip+'/original/getRequireById?callback=update&id='+_id;
        $.ajax({
            url:url,
            type: 'GET',
            dataType: 'jsonp',
            contentType:'application/json',
            jsonpCallback: 'update',
            success:function(data){
                if(data.success){
                    var data = data.data;
                    $('#document-name').append('ID.'+data.id);
                    $('#needName').html(data.name);
                    $('#projectName').html(data.projectName);
                    $('#needSide').html(data.customerName);
                    $('#typeList').html(data.type);
                    $('#productList').html(data.product);
                    $('#platformList').html(data.plat);
                    $('#functionList').html(data.feature);
                    $('#levelList').html(data.level);
                    $('#reliableList').html(data.reliableDesc);
                    $('#scenario').html(data.scenario);
                    $('#nowSolution').html(data.nowSolution);
                    $('#sugSolution').html(data.sugSolution);
                    if(data.attachment){
                        attachment.init({
                            addAttachmentList:$('#addAttachmentList'),
                            isDetail:true
                        }).getAttachmentList(data.attachment.split(',')); 
                    }
                    //权限控制
                    var roleid = $.cookie('userrole');
                    if( ((roleid==1 || roleid==2 || roleid==3) && data.creater == $.cookie('username') && data.status=='待处理') || roleid==9 || roleid== 0){
                        $('#needEdit').show()
                    }else{
                        $('#needEdit').hide();
                    }

                }else{
                    alert('获取失败, 请稍后重试！');
                }
            }
        })
    }
    updata();


    // creatShare();
    function creatShare(){

        var html = '';
        html += '<div class="share-box">';
            html += '<p class="relative-title">关联已有需求</p>';
            html += '<div class="con-box">';
                html += '<div class="search clear">';
                    html += '<i class="icon left"></i>';
                    html += '<input placeholder="输入产品名称或主题关键字" class="left" id="JS_search" style="border: 0px;height: 33px"/>';
                html += '</div>';
                html += '<div class="search-box" id="JS_search_box"><table class="search-table"><tbody  id="JS_searchTable"> ';

                    html += '<tr><td><label><input value="1" type="checkbox"/>合同管理|合同导出</label></td><td>医信云服1.0 </td><td>后台</td></tr>';
                   


                html += '<tbody></table></div>'
            html += '</div>';
            html += '<div class="buttons"><a class="cancel" href="javascript:$$.closeLayer()">取消</a><a id="confirmRelative" class="confirm">确认</a></div>'
        html += '</div>';
        $$.layer(html, {
            isShowMask: true,
            fixedBoxTop:'100px',
            zIndex:99,
            contentBoxWidth: "55%"
        });

        $('#JS_search').keyup(function() {

            var _val = $(this).val();
            var _h   = getKeyList(_val);
            if(_val == ''){
                $('#JS_search_box').hide();
            }
        })

        var checkbox = [];
        $('#confirmRelative').click(function(){
            $('#JS_searchTable').find('tr').each(function(){
                var check = $(this).find('input[type=checkbox]')
                var prop  = check.prop('checked');
                if(prop){
                    checkbox.push(check.val())
                }
            })
            
            if(checkbox.length >= 1){

                var url  = _ip+'/requireRelation/addRequireRelation?oid='+_id+'&pid='+checkbox.join(',');
                $.ajax({
                    url:url,
                    type: 'GET',
                    dataType: 'jsonp',
                    contentType:'application/json',
                    jsonpCallback: 'update',
                    success:function(data){
                        location.reload()
                    }
                })
            }
        })
    }


    function getKeyList(name){
        var data = {'name':name,'oid':_id};
        var url  = _ip+'/product/searchRequire?name='+name+'&oid='+_id;
        
        var h = '';
        $.ajax({
            url:url,
            dataType: 'jsonp',
            contentType:'application/json',
            jsonpCallback: 'getpro',
            async: false,
            success:function(json){
                var json = json.data;
                if(json.length >= 1){
                    for(var k = 0; k < json.length; k ++){
                        h += '<tr class="'+(json[k].checked?'current':'')+'"><td><label><input value="'+json[k].id+'" type="checkbox" '+(json[k].checked?'disabled="disabled" checked="checked"':'')+' />'+json[k].name+'|'+json[k].feature+'</label></td><td>'+json[k].product+'</td><td>'+json[k].status+'</td></td><td>'+json[k].plat+'</td></tr>';
                    }
                }
                if( h  ){
                    $('#JS_searchTable').html(h);
                    $('#JS_search_box').show();
                }else{
                    $('#JS_search_box').hide();
                }
                
            }
        })
    }

    getRelativList();

    function getRelativList(){
        var url  = _ip+'/requireRelation/getRequireRelationByOid?oid='+_id;        
        $.ajax({
            url:url,
            type: 'GET',
            dataType: 'jsonp',
            contentType:'application/json',
            jsonpCallback: 'off',
            success:function(data){
//                console.log(data);
                var data = data.data;
                var h = '';
                if(!data.length) {
                    $('#relativeList').html('<tr><td colspan="6" style="text-align: center">暂无数据！</td></tr>');
                    return false;
                }
                for(var k = 0; k < data.length; k++){
                    h += '<tr><td>'+data[k].productName+'</td>';
                        h += '<td>'+data[k].feature+'</td>';
                        h += '<td><a href="pm-need-detail-pm.html?id='+data[k].id+'">'+data[k].pName+'</a></td>';
                        h += '<td>'+data[k].priority+'</td>';
                        h += '<td>'+data[k].status+'</td>';

                        if(roleid == 1 || roleid == 2 || roleid == 3){
                            h += '<td></td></tr>';
                        }else if(roleid ==0 || roleid == 9){
                            h += '<td><a class="delete" onclick="callOff('+data[k].pId+','+data[k].oId+')">解绑</a></td></tr>';
                        }

                }
                $('#relativeList').html(h);
            }
        })
    }
    function callOff(pid,oid){
        if(confirm('确认解绑？')){
            var url  = _ip+'/requireRelation/deleteRequireRelation?pid='+pid+'&oid='+oid;
            $.ajax({
                url:url,
                type: 'GET',
                dataType: 'jsonp',
                contentType:'application/json',
                jsonpCallback: 'off',
                success:function(data){
                    if (data.success) {
                        location.reload();
                    }
                }
            })
        }

    }

</script>
</body>
</html>